<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/boost/algorithm/string/detail/finder.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../../../index.html">top level</a> - <a href="index.html">usr/include/boost/algorithm/string/detail</a> - finder.hpp<span style="font-size: 80%;"> (source / <a href="finder.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">6</td>
            <td class="headerCovTableEntry">9</td>
            <td class="headerCovTableEntryLo">66.7 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">1</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntryLo">50.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : //  Boost string_algo library finder.hpp header file  ---------------------------//</a>
<span class="lineNum">       2 </span>            : 
<span class="lineNum">       3 </span>            : //  Copyright Pavol Droba 2002-2006.
<span class="lineNum">       4 </span>            : //
<span class="lineNum">       5 </span>            : // Distributed under the Boost Software License, Version 1.0.
<span class="lineNum">       6 </span>            : //    (See accompanying file LICENSE_1_0.txt or copy at
<span class="lineNum">       7 </span>            : //          http://www.boost.org/LICENSE_1_0.txt)
<span class="lineNum">       8 </span>            : 
<span class="lineNum">       9 </span>            : //  See http://www.boost.org/ for updates, documentation, and revision history.
<span class="lineNum">      10 </span>            : 
<span class="lineNum">      11 </span>            : #ifndef BOOST_STRING_FINDER_DETAIL_HPP
<span class="lineNum">      12 </span>            : #define BOOST_STRING_FINDER_DETAIL_HPP
<span class="lineNum">      13 </span>            : 
<span class="lineNum">      14 </span>            : #include &lt;boost/algorithm/string/config.hpp&gt;
<span class="lineNum">      15 </span>            : #include &lt;boost/algorithm/string/constants.hpp&gt;
<span class="lineNum">      16 </span>            : #include &lt;boost/detail/iterator.hpp&gt;
<span class="lineNum">      17 </span>            : 
<span class="lineNum">      18 </span>            : #include &lt;boost/range/iterator_range_core.hpp&gt;
<span class="lineNum">      19 </span>            : #include &lt;boost/range/begin.hpp&gt;
<span class="lineNum">      20 </span>            : #include &lt;boost/range/end.hpp&gt;
<span class="lineNum">      21 </span>            : #include &lt;boost/range/empty.hpp&gt;
<span class="lineNum">      22 </span>            : #include &lt;boost/range/as_literal.hpp&gt;
<span class="lineNum">      23 </span>            : 
<span class="lineNum">      24 </span>            : namespace boost {
<span class="lineNum">      25 </span>            :     namespace algorithm {
<span class="lineNum">      26 </span>            :         namespace detail {
<span class="lineNum">      27 </span>            : 
<span class="lineNum">      28 </span>            : 
<span class="lineNum">      29 </span>            : //  find first functor -----------------------------------------------//
<span class="lineNum">      30 </span>            : 
<span class="lineNum">      31 </span>            :             // find a subsequence in the sequence ( functor )
<span class="lineNum">      32 </span>            :             /*
<span class="lineNum">      33 </span>            :                 Returns a pair &lt;begin,end&gt; marking the subsequence in the sequence.
<span class="lineNum">      34 </span>            :                 If the find fails, functor returns &lt;End,End&gt;
<span class="lineNum">      35 </span>            :             */
<span class="lineNum">      36 </span>            :             template&lt;typename SearchIteratorT,typename PredicateT&gt;
<span class="lineNum">      37 </span>            :             struct first_finderF
<span class="lineNum">      38 </span>            :             {
<span class="lineNum">      39 </span>            :                 typedef SearchIteratorT search_iterator_type;
<span class="lineNum">      40 </span>            : 
<span class="lineNum">      41 </span>            :                 // Construction
<span class="lineNum">      42 </span>            :                 template&lt; typename SearchT &gt;
<span class="lineNum">      43 </span>            :                 first_finderF( const SearchT&amp; Search, PredicateT Comp ) :
<span class="lineNum">      44 </span>            :                     m_Search(::boost::begin(Search), ::boost::end(Search)), m_Comp(Comp) {}
<span class="lineNum">      45 </span>            :                 first_finderF(
<span class="lineNum">      46 </span>            :                         search_iterator_type SearchBegin,
<span class="lineNum">      47 </span>            :                         search_iterator_type SearchEnd,
<span class="lineNum">      48 </span>            :                         PredicateT Comp ) :
<span class="lineNum">      49 </span>            :                     m_Search(SearchBegin, SearchEnd), m_Comp(Comp) {}
<span class="lineNum">      50 </span>            : 
<span class="lineNum">      51 </span>            :                 // Operation
<span class="lineNum">      52 </span>            :                 template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">      53 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">      54 </span>            :                 operator()(
<span class="lineNum">      55 </span>            :                     ForwardIteratorT Begin,
<span class="lineNum">      56 </span>            :                     ForwardIteratorT End ) const
<span class="lineNum">      57 </span>            :                 {
<span class="lineNum">      58 </span>            :                     typedef iterator_range&lt;ForwardIteratorT&gt; result_type;
<span class="lineNum">      59 </span>            :                     typedef ForwardIteratorT input_iterator_type;
<span class="lineNum">      60 </span>            : 
<span class="lineNum">      61 </span>            :                     // Outer loop
<span class="lineNum">      62 </span>            :                     for(input_iterator_type OuterIt=Begin;
<span class="lineNum">      63 </span>            :                         OuterIt!=End;
<span class="lineNum">      64 </span>            :                         ++OuterIt)
<span class="lineNum">      65 </span>            :                     {
<span class="lineNum">      66 </span>            :                         // Sanity check
<span class="lineNum">      67 </span>            :                         if( boost::empty(m_Search) )
<span class="lineNum">      68 </span>            :                             return result_type( End, End );
<span class="lineNum">      69 </span>            : 
<span class="lineNum">      70 </span>            :                         input_iterator_type InnerIt=OuterIt;
<span class="lineNum">      71 </span>            :                         search_iterator_type SubstrIt=m_Search.begin();
<span class="lineNum">      72 </span>            :                         for(;
<span class="lineNum">      73 </span>            :                             InnerIt!=End &amp;&amp; SubstrIt!=m_Search.end();
<span class="lineNum">      74 </span>            :                             ++InnerIt,++SubstrIt)
<span class="lineNum">      75 </span>            :                         {
<span class="lineNum">      76 </span>            :                             if( !( m_Comp(*InnerIt,*SubstrIt) ) )
<span class="lineNum">      77 </span>            :                                 break;
<span class="lineNum">      78 </span>            :                         }
<span class="lineNum">      79 </span>            : 
<span class="lineNum">      80 </span>            :                         // Substring matching succeeded
<span class="lineNum">      81 </span>            :                         if ( SubstrIt==m_Search.end() )
<span class="lineNum">      82 </span>            :                             return result_type( OuterIt, InnerIt );
<span class="lineNum">      83 </span>            :                     }
<span class="lineNum">      84 </span>            : 
<span class="lineNum">      85 </span>            :                     return result_type( End, End );
<span class="lineNum">      86 </span>            :                 }
<span class="lineNum">      87 </span>            : 
<span class="lineNum">      88 </span>            :             private:
<span class="lineNum">      89 </span>            :                 iterator_range&lt;search_iterator_type&gt; m_Search;
<span class="lineNum">      90 </span>            :                 PredicateT m_Comp;
<span class="lineNum">      91 </span>            :             };
<span class="lineNum">      92 </span>            : 
<span class="lineNum">      93 </span>            : //  find last functor -----------------------------------------------//
<span class="lineNum">      94 </span>            : 
<span class="lineNum">      95 </span>            :             // find the last match a subsequence in the sequence ( functor )
<span class="lineNum">      96 </span>            :             /*
<span class="lineNum">      97 </span>            :                 Returns a pair &lt;begin,end&gt; marking the subsequence in the sequence.
<span class="lineNum">      98 </span>            :                 If the find fails, returns &lt;End,End&gt;
<span class="lineNum">      99 </span>            :             */
<span class="lineNum">     100 </span>            :             template&lt;typename SearchIteratorT, typename PredicateT&gt;
<span class="lineNum">     101 </span>            :             struct last_finderF
<span class="lineNum">     102 </span>            :             {
<span class="lineNum">     103 </span>            :                 typedef SearchIteratorT search_iterator_type;
<span class="lineNum">     104 </span>            :                 typedef first_finderF&lt;
<span class="lineNum">     105 </span>            :                     search_iterator_type,
<span class="lineNum">     106 </span>            :                     PredicateT&gt; first_finder_type;
<span class="lineNum">     107 </span>            : 
<span class="lineNum">     108 </span>            :                 // Construction
<span class="lineNum">     109 </span>            :                 template&lt; typename SearchT &gt;
<span class="lineNum">     110 </span>            :                 last_finderF( const SearchT&amp; Search, PredicateT Comp ) :
<span class="lineNum">     111 </span>            :                     m_Search(::boost::begin(Search), ::boost::end(Search)), m_Comp(Comp) {}
<span class="lineNum">     112 </span>            :                 last_finderF(
<span class="lineNum">     113 </span>            :                         search_iterator_type SearchBegin,
<span class="lineNum">     114 </span>            :                         search_iterator_type SearchEnd,
<span class="lineNum">     115 </span>            :                         PredicateT Comp ) :
<span class="lineNum">     116 </span>            :                     m_Search(SearchBegin, SearchEnd), m_Comp(Comp) {}
<span class="lineNum">     117 </span>            : 
<span class="lineNum">     118 </span>            :                 // Operation
<span class="lineNum">     119 </span>            :                 template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">     120 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     121 </span>            :                 operator()(
<span class="lineNum">     122 </span>            :                     ForwardIteratorT Begin,
<span class="lineNum">     123 </span>            :                     ForwardIteratorT End ) const
<span class="lineNum">     124 </span>            :                 {
<span class="lineNum">     125 </span>            :                     typedef iterator_range&lt;ForwardIteratorT&gt; result_type;
<span class="lineNum">     126 </span>            : 
<span class="lineNum">     127 </span>            :                     if( boost::empty(m_Search) )
<span class="lineNum">     128 </span>            :                         return result_type( End, End );
<span class="lineNum">     129 </span>            : 
<span class="lineNum">     130 </span>            :                     typedef BOOST_STRING_TYPENAME boost::detail::
<span class="lineNum">     131 </span>            :                         iterator_traits&lt;ForwardIteratorT&gt;::iterator_category category;
<span class="lineNum">     132 </span>            : 
<span class="lineNum">     133 </span>            :                     return findit( Begin, End, category() );
<span class="lineNum">     134 </span>            :                 }
<span class="lineNum">     135 </span>            : 
<span class="lineNum">     136 </span>            :             private:
<span class="lineNum">     137 </span>            :                 // forward iterator
<span class="lineNum">     138 </span>            :                 template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">     139 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     140 </span>            :                 findit(
<span class="lineNum">     141 </span>            :                     ForwardIteratorT Begin,
<span class="lineNum">     142 </span>            :                     ForwardIteratorT End,
<span class="lineNum">     143 </span>            :                     std::forward_iterator_tag ) const
<span class="lineNum">     144 </span>            :                 {
<span class="lineNum">     145 </span>            :                     typedef iterator_range&lt;ForwardIteratorT&gt; result_type;
<span class="lineNum">     146 </span>            : 
<span class="lineNum">     147 </span>            :                     first_finder_type first_finder(
<span class="lineNum">     148 </span>            :                         m_Search.begin(), m_Search.end(), m_Comp );
<span class="lineNum">     149 </span>            : 
<span class="lineNum">     150 </span>            :                     result_type M=first_finder( Begin, End );
<span class="lineNum">     151 </span>            :                     result_type Last=M;
<span class="lineNum">     152 </span>            : 
<span class="lineNum">     153 </span>            :                     while( M )
<span class="lineNum">     154 </span>            :                     {
<span class="lineNum">     155 </span>            :                         Last=M;
<span class="lineNum">     156 </span>            :                         M=first_finder( ::boost::end(M), End );
<span class="lineNum">     157 </span>            :                     }
<span class="lineNum">     158 </span>            : 
<span class="lineNum">     159 </span>            :                     return Last;
<span class="lineNum">     160 </span>            :                 }
<span class="lineNum">     161 </span>            : 
<span class="lineNum">     162 </span>            :                 // bidirectional iterator
<span class="lineNum">     163 </span>            :                 template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">     164 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     165 </span>            :                 findit(
<span class="lineNum">     166 </span>            :                     ForwardIteratorT Begin,
<span class="lineNum">     167 </span>            :                     ForwardIteratorT End,
<span class="lineNum">     168 </span>            :                     std::bidirectional_iterator_tag ) const
<span class="lineNum">     169 </span>            :                 {
<span class="lineNum">     170 </span>            :                     typedef iterator_range&lt;ForwardIteratorT&gt; result_type;
<span class="lineNum">     171 </span>            :                     typedef ForwardIteratorT input_iterator_type;
<span class="lineNum">     172 </span>            : 
<span class="lineNum">     173 </span>            :                     // Outer loop
<span class="lineNum">     174 </span>            :                     for(input_iterator_type OuterIt=End;
<span class="lineNum">     175 </span>            :                         OuterIt!=Begin; )
<span class="lineNum">     176 </span>            :                     {
<span class="lineNum">     177 </span>            :                         input_iterator_type OuterIt2=--OuterIt;
<span class="lineNum">     178 </span>            : 
<span class="lineNum">     179 </span>            :                         input_iterator_type InnerIt=OuterIt2;
<span class="lineNum">     180 </span>            :                         search_iterator_type SubstrIt=m_Search.begin();
<span class="lineNum">     181 </span>            :                         for(;
<span class="lineNum">     182 </span>            :                             InnerIt!=End &amp;&amp; SubstrIt!=m_Search.end();
<span class="lineNum">     183 </span>            :                             ++InnerIt,++SubstrIt)
<span class="lineNum">     184 </span>            :                         {
<span class="lineNum">     185 </span>            :                             if( !( m_Comp(*InnerIt,*SubstrIt) ) )
<span class="lineNum">     186 </span>            :                                 break;
<span class="lineNum">     187 </span>            :                         }
<span class="lineNum">     188 </span>            : 
<span class="lineNum">     189 </span>            :                         // Substring matching succeeded
<span class="lineNum">     190 </span>            :                         if( SubstrIt==m_Search.end() )
<span class="lineNum">     191 </span>            :                             return result_type( OuterIt2, InnerIt );
<span class="lineNum">     192 </span>            :                     }
<span class="lineNum">     193 </span>            : 
<span class="lineNum">     194 </span>            :                     return result_type( End, End );
<span class="lineNum">     195 </span>            :                 }
<span class="lineNum">     196 </span>            : 
<span class="lineNum">     197 </span>            :             private:
<span class="lineNum">     198 </span>            :                 iterator_range&lt;search_iterator_type&gt; m_Search;
<span class="lineNum">     199 </span>            :                 PredicateT m_Comp;
<span class="lineNum">     200 </span>            :             };
<span class="lineNum">     201 </span>            : 
<span class="lineNum">     202 </span>            : //  find n-th functor -----------------------------------------------//
<span class="lineNum">     203 </span>            : 
<span class="lineNum">     204 </span>            :             // find the n-th match of a subsequence in the sequence ( functor )
<span class="lineNum">     205 </span>            :             /*
<span class="lineNum">     206 </span>            :                 Returns a pair &lt;begin,end&gt; marking the subsequence in the sequence.
<span class="lineNum">     207 </span>            :                 If the find fails, returns &lt;End,End&gt;
<span class="lineNum">     208 </span>            :             */
<span class="lineNum">     209 </span>            :             template&lt;typename SearchIteratorT, typename PredicateT&gt;
<span class="lineNum">     210 </span>            :             struct nth_finderF
<span class="lineNum">     211 </span>            :             {
<span class="lineNum">     212 </span>            :                 typedef SearchIteratorT search_iterator_type;
<span class="lineNum">     213 </span>            :                 typedef first_finderF&lt;
<span class="lineNum">     214 </span>            :                     search_iterator_type,
<span class="lineNum">     215 </span>            :                     PredicateT&gt; first_finder_type;
<span class="lineNum">     216 </span>            :                 typedef last_finderF&lt;
<span class="lineNum">     217 </span>            :                     search_iterator_type,
<span class="lineNum">     218 </span>            :                     PredicateT&gt; last_finder_type;
<span class="lineNum">     219 </span>            : 
<span class="lineNum">     220 </span>            :                 // Construction
<span class="lineNum">     221 </span>            :                 template&lt; typename SearchT &gt;
<span class="lineNum">     222 </span>            :                 nth_finderF(
<span class="lineNum">     223 </span>            :                         const SearchT&amp; Search,
<span class="lineNum">     224 </span>            :                         int Nth,
<span class="lineNum">     225 </span>            :                         PredicateT Comp) :
<span class="lineNum">     226 </span>            :                     m_Search(::boost::begin(Search), ::boost::end(Search)),
<span class="lineNum">     227 </span>            :                     m_Nth(Nth),
<span class="lineNum">     228 </span>            :                     m_Comp(Comp) {}
<span class="lineNum">     229 </span>            :                 nth_finderF(
<span class="lineNum">     230 </span>            :                         search_iterator_type SearchBegin,
<span class="lineNum">     231 </span>            :                         search_iterator_type SearchEnd,
<span class="lineNum">     232 </span>            :                         int Nth,
<span class="lineNum">     233 </span>            :                         PredicateT Comp) :
<span class="lineNum">     234 </span>            :                     m_Search(SearchBegin, SearchEnd),
<span class="lineNum">     235 </span>            :                     m_Nth(Nth),
<span class="lineNum">     236 </span>            :                     m_Comp(Comp) {}
<span class="lineNum">     237 </span>            : 
<span class="lineNum">     238 </span>            :                 // Operation
<span class="lineNum">     239 </span>            :                 template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">     240 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     241 </span>            :                 operator()(
<span class="lineNum">     242 </span>            :                     ForwardIteratorT Begin,
<span class="lineNum">     243 </span>            :                     ForwardIteratorT End ) const
<span class="lineNum">     244 </span>            :                 {
<span class="lineNum">     245 </span>            :                     if(m_Nth&gt;=0)
<span class="lineNum">     246 </span>            :                     {
<span class="lineNum">     247 </span>            :                         return find_forward(Begin, End, m_Nth);
<span class="lineNum">     248 </span>            :                     }
<span class="lineNum">     249 </span>            :                     else
<span class="lineNum">     250 </span>            :                     {
<span class="lineNum">     251 </span>            :                         return find_backward(Begin, End, -m_Nth);
<span class="lineNum">     252 </span>            :                     }
<span class="lineNum">     253 </span>            : 
<span class="lineNum">     254 </span>            :                 }
<span class="lineNum">     255 </span>            : 
<span class="lineNum">     256 </span>            :             private:
<span class="lineNum">     257 </span>            :                 // Implementation helpers
<span class="lineNum">     258 </span>            :                 template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">     259 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     260 </span>            :                 find_forward(
<span class="lineNum">     261 </span>            :                     ForwardIteratorT Begin,
<span class="lineNum">     262 </span>            :                     ForwardIteratorT End,
<span class="lineNum">     263 </span>            :                     unsigned int N) const
<span class="lineNum">     264 </span>            :                 {
<span class="lineNum">     265 </span>            :                     typedef iterator_range&lt;ForwardIteratorT&gt; result_type;
<span class="lineNum">     266 </span>            : 
<span class="lineNum">     267 </span>            :                     // Sanity check
<span class="lineNum">     268 </span>            :                     if( boost::empty(m_Search) )
<span class="lineNum">     269 </span>            :                         return result_type( End, End );
<span class="lineNum">     270 </span>            : 
<span class="lineNum">     271 </span>            :                     // Instantiate find functor
<span class="lineNum">     272 </span>            :                     first_finder_type first_finder(
<span class="lineNum">     273 </span>            :                         m_Search.begin(), m_Search.end(), m_Comp );
<span class="lineNum">     274 </span>            : 
<span class="lineNum">     275 </span>            :                     result_type M( Begin, Begin );
<span class="lineNum">     276 </span>            : 
<span class="lineNum">     277 </span>            :                     for( unsigned int n=0; n&lt;=N; ++n )
<span class="lineNum">     278 </span>            :                     {
<span class="lineNum">     279 </span>            :                         // find next match
<span class="lineNum">     280 </span>            :                         M=first_finder( ::boost::end(M), End );
<span class="lineNum">     281 </span>            : 
<span class="lineNum">     282 </span>            :                         if ( !M )
<span class="lineNum">     283 </span>            :                         {
<span class="lineNum">     284 </span>            :                             // Subsequence not found, return
<span class="lineNum">     285 </span>            :                             return M;
<span class="lineNum">     286 </span>            :                         }
<span class="lineNum">     287 </span>            :                     }
<span class="lineNum">     288 </span>            : 
<span class="lineNum">     289 </span>            :                     return M;
<span class="lineNum">     290 </span>            :                 }
<span class="lineNum">     291 </span>            : 
<span class="lineNum">     292 </span>            :                 template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">     293 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     294 </span>            :                 find_backward(
<span class="lineNum">     295 </span>            :                     ForwardIteratorT Begin,
<span class="lineNum">     296 </span>            :                     ForwardIteratorT End,
<span class="lineNum">     297 </span>            :                     unsigned int N) const
<span class="lineNum">     298 </span>            :                 {
<span class="lineNum">     299 </span>            :                     typedef iterator_range&lt;ForwardIteratorT&gt; result_type;
<span class="lineNum">     300 </span>            : 
<span class="lineNum">     301 </span>            :                     // Sanity check
<span class="lineNum">     302 </span>            :                     if( boost::empty(m_Search) )
<span class="lineNum">     303 </span>            :                         return result_type( End, End );
<span class="lineNum">     304 </span>            : 
<span class="lineNum">     305 </span>            :                     // Instantiate find functor
<span class="lineNum">     306 </span>            :                     last_finder_type last_finder(
<span class="lineNum">     307 </span>            :                         m_Search.begin(), m_Search.end(), m_Comp );
<span class="lineNum">     308 </span>            : 
<span class="lineNum">     309 </span>            :                     result_type M( End, End );
<span class="lineNum">     310 </span>            : 
<span class="lineNum">     311 </span>            :                     for( unsigned int n=1; n&lt;=N; ++n )
<span class="lineNum">     312 </span>            :                     {
<span class="lineNum">     313 </span>            :                         // find next match
<span class="lineNum">     314 </span>            :                         M=last_finder( Begin, ::boost::begin(M) );
<span class="lineNum">     315 </span>            : 
<span class="lineNum">     316 </span>            :                         if ( !M )
<span class="lineNum">     317 </span>            :                         {
<span class="lineNum">     318 </span>            :                             // Subsequence not found, return
<span class="lineNum">     319 </span>            :                             return M;
<span class="lineNum">     320 </span>            :                         }
<span class="lineNum">     321 </span>            :                     }
<span class="lineNum">     322 </span>            : 
<span class="lineNum">     323 </span>            :                     return M;
<span class="lineNum">     324 </span>            :                 }
<span class="lineNum">     325 </span>            : 
<span class="lineNum">     326 </span>            : 
<span class="lineNum">     327 </span>            :             private:
<span class="lineNum">     328 </span>            :                 iterator_range&lt;search_iterator_type&gt; m_Search;
<span class="lineNum">     329 </span>            :                 int m_Nth;
<span class="lineNum">     330 </span>            :                 PredicateT m_Comp;
<span class="lineNum">     331 </span>            :             };
<span class="lineNum">     332 </span>            : 
<span class="lineNum">     333 </span>            : //  find head/tail implementation helpers ---------------------------//
<span class="lineNum">     334 </span>            : 
<span class="lineNum">     335 </span>            :             template&lt;typename ForwardIteratorT&gt;
<span class="lineNum">     336 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     337 </span>            :             find_head_impl(
<span class="lineNum">     338 </span>            :                 ForwardIteratorT Begin,
<span class="lineNum">     339 </span>            :                 ForwardIteratorT End,
<span class="lineNum">     340 </span>            :                 unsigned int N,
<span class="lineNum">     341 </span>            :                 std::forward_iterator_tag )
<span class="lineNum">     342 </span>            :             {
<span class="lineNum">     343 </span>            :                 typedef ForwardIteratorT input_iterator_type;
<span class="lineNum">     344 </span>            :                 typedef iterator_range&lt;ForwardIteratorT&gt; result_type;
<span class="lineNum">     345 </span>            : 
<span class="lineNum">     346 </span>            :                 input_iterator_type It=Begin;
<span class="lineNum">     347 </span>            :                 for(
<span class="lineNum">     348 </span>            :                     unsigned int Index=0;
<span class="lineNum">     349 </span>            :                     Index&lt;N &amp;&amp; It!=End; ++Index,++It ) {};
<span class="lineNum">     350 </span>            : 
<span class="lineNum">     351 </span>            :                 return result_type( Begin, It );
<span class="lineNum">     352 </span>            :             }
<span class="lineNum">     353 </span>            : 
<span class="lineNum">     354 </span>            :             template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">     355 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     356 </span>            :             find_head_impl(
<span class="lineNum">     357 </span>            :                 ForwardIteratorT Begin,
<span class="lineNum">     358 </span>            :                 ForwardIteratorT End,
<span class="lineNum">     359 </span>            :                 unsigned int N,
<span class="lineNum">     360 </span>            :                 std::random_access_iterator_tag )
<span class="lineNum">     361 </span>            :             {
<span class="lineNum">     362 </span>            :                 typedef iterator_range&lt;ForwardIteratorT&gt; result_type;
<span class="lineNum">     363 </span>            : 
<span class="lineNum">     364 </span>            :                 if ( (End&lt;=Begin) || ( static_cast&lt;unsigned int&gt;(End-Begin) &lt; N ) )
<span class="lineNum">     365 </span>            :                     return result_type( Begin, End );
<span class="lineNum">     366 </span>            : 
<span class="lineNum">     367 </span>            :                 return result_type(Begin,Begin+N);
<span class="lineNum">     368 </span>            :             }
<span class="lineNum">     369 </span>            : 
<span class="lineNum">     370 </span>            :             // Find head implementation
<span class="lineNum">     371 </span>            :             template&lt;typename ForwardIteratorT&gt;
<span class="lineNum">     372 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     373 </span>            :             find_head_impl(
<span class="lineNum">     374 </span>            :                 ForwardIteratorT Begin,
<span class="lineNum">     375 </span>            :                 ForwardIteratorT End,
<span class="lineNum">     376 </span>            :                 unsigned int N )
<span class="lineNum">     377 </span>            :             {
<span class="lineNum">     378 </span>            :                 typedef BOOST_STRING_TYPENAME boost::detail::
<span class="lineNum">     379 </span>            :                     iterator_traits&lt;ForwardIteratorT&gt;::iterator_category category;
<span class="lineNum">     380 </span>            : 
<span class="lineNum">     381 </span>            :                 return ::boost::algorithm::detail::find_head_impl( Begin, End, N, category() );
<span class="lineNum">     382 </span>            :             }
<span class="lineNum">     383 </span>            : 
<span class="lineNum">     384 </span>            :             template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">     385 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     386 </span>            :             find_tail_impl(
<span class="lineNum">     387 </span>            :                 ForwardIteratorT Begin,
<span class="lineNum">     388 </span>            :                 ForwardIteratorT End,
<span class="lineNum">     389 </span>            :                 unsigned int N,
<span class="lineNum">     390 </span>            :                 std::forward_iterator_tag )
<span class="lineNum">     391 </span>            :             {
<span class="lineNum">     392 </span>            :                 typedef ForwardIteratorT input_iterator_type;
<span class="lineNum">     393 </span>            :                 typedef iterator_range&lt;ForwardIteratorT&gt; result_type;
<span class="lineNum">     394 </span>            : 
<span class="lineNum">     395 </span>            :                 unsigned int Index=0;
<span class="lineNum">     396 </span>            :                 input_iterator_type It=Begin;
<span class="lineNum">     397 </span>            :                 input_iterator_type It2=Begin;
<span class="lineNum">     398 </span>            : 
<span class="lineNum">     399 </span>            :                 // Advance It2 by N increments
<span class="lineNum">     400 </span>            :                 for( Index=0; Index&lt;N &amp;&amp; It2!=End; ++Index,++It2 ) {};
<span class="lineNum">     401 </span>            : 
<span class="lineNum">     402 </span>            :                 // Advance It, It2 to the end
<span class="lineNum">     403 </span>            :                 for(; It2!=End; ++It,++It2 ) {};
<span class="lineNum">     404 </span>            : 
<span class="lineNum">     405 </span>            :                 return result_type( It, It2 );
<span class="lineNum">     406 </span>            :             }
<span class="lineNum">     407 </span>            : 
<span class="lineNum">     408 </span>            :             template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">     409 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     410 </span>            :             find_tail_impl(
<span class="lineNum">     411 </span>            :                 ForwardIteratorT Begin,
<span class="lineNum">     412 </span>            :                 ForwardIteratorT End,
<span class="lineNum">     413 </span>            :                 unsigned int N,
<span class="lineNum">     414 </span>            :                 std::bidirectional_iterator_tag )
<span class="lineNum">     415 </span>            :             {
<span class="lineNum">     416 </span>            :                 typedef ForwardIteratorT input_iterator_type;
<span class="lineNum">     417 </span>            :                 typedef iterator_range&lt;ForwardIteratorT&gt; result_type;
<span class="lineNum">     418 </span>            : 
<span class="lineNum">     419 </span>            :                 input_iterator_type It=End;
<span class="lineNum">     420 </span>            :                 for(
<span class="lineNum">     421 </span>            :                     unsigned int Index=0;
<span class="lineNum">     422 </span>            :                     Index&lt;N &amp;&amp; It!=Begin; ++Index,--It ) {};
<span class="lineNum">     423 </span>            : 
<span class="lineNum">     424 </span>            :                 return result_type( It, End );
<span class="lineNum">     425 </span>            :             }
<span class="lineNum">     426 </span>            : 
<span class="lineNum">     427 </span>            :             template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">     428 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     429 </span>            :             find_tail_impl(
<span class="lineNum">     430 </span>            :                 ForwardIteratorT Begin,
<span class="lineNum">     431 </span>            :                 ForwardIteratorT End,
<span class="lineNum">     432 </span>            :                 unsigned int N,
<span class="lineNum">     433 </span>            :                 std::random_access_iterator_tag )
<span class="lineNum">     434 </span>            :             {
<span class="lineNum">     435 </span>            :                 typedef iterator_range&lt;ForwardIteratorT&gt; result_type;
<span class="lineNum">     436 </span>            : 
<span class="lineNum">     437 </span>            :                 if ( (End&lt;=Begin) || ( static_cast&lt;unsigned int&gt;(End-Begin) &lt; N ) )
<span class="lineNum">     438 </span>            :                     return result_type( Begin, End );
<span class="lineNum">     439 </span>            : 
<span class="lineNum">     440 </span>            :                 return result_type( End-N, End );
<span class="lineNum">     441 </span>            :             }
<span class="lineNum">     442 </span>            : 
<span class="lineNum">     443 </span>            :                         // Operation
<span class="lineNum">     444 </span>            :             template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">     445 </span>            :             iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     446 </span>            :             find_tail_impl(
<span class="lineNum">     447 </span>            :                 ForwardIteratorT Begin,
<span class="lineNum">     448 </span>            :                 ForwardIteratorT End,
<span class="lineNum">     449 </span>            :                 unsigned int N )
<span class="lineNum">     450 </span>            :             {
<span class="lineNum">     451 </span>            :                 typedef BOOST_STRING_TYPENAME boost::detail::
<span class="lineNum">     452 </span>            :                     iterator_traits&lt;ForwardIteratorT&gt;::iterator_category category;
<span class="lineNum">     453 </span>            : 
<span class="lineNum">     454 </span>            :                 return ::boost::algorithm::detail::find_tail_impl( Begin, End, N, category() );
<span class="lineNum">     455 </span>            :             }
<span class="lineNum">     456 </span>            : 
<span class="lineNum">     457 </span>            : 
<span class="lineNum">     458 </span>            : 
<span class="lineNum">     459 </span>            : //  find head functor -----------------------------------------------//
<span class="lineNum">     460 </span>            : 
<span class="lineNum">     461 </span>            : 
<span class="lineNum">     462 </span>            :             // find a head in the sequence ( functor )
<span class="lineNum">     463 </span>            :             /*
<span class="lineNum">     464 </span>            :                 This functor find a head of the specified range. For
<span class="lineNum">     465 </span>            :                 a specified N, the head is a subsequence of N starting
<span class="lineNum">     466 </span>            :                 elements of the range.
<span class="lineNum">     467 </span>            :             */
<span class="lineNum">     468 </span>            :             struct head_finderF
<span class="lineNum">     469 </span>            :             {
<span class="lineNum">     470 </span>            :                 // Construction
<span class="lineNum">     471 </span>            :                 head_finderF( int N ) : m_N(N) {}
<span class="lineNum">     472 </span>            : 
<span class="lineNum">     473 </span>            :                 // Operation
<span class="lineNum">     474 </span>            :                 template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">     475 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     476 </span>            :                 operator()(
<span class="lineNum">     477 </span>            :                     ForwardIteratorT Begin,
<span class="lineNum">     478 </span>            :                     ForwardIteratorT End ) const
<span class="lineNum">     479 </span>            :                 {
<span class="lineNum">     480 </span>            :                     if(m_N&gt;=0)
<span class="lineNum">     481 </span>            :                     {
<span class="lineNum">     482 </span>            :                         return ::boost::algorithm::detail::find_head_impl( Begin, End, m_N );
<span class="lineNum">     483 </span>            :                     }
<span class="lineNum">     484 </span>            :                     else
<span class="lineNum">     485 </span>            :                     {
<span class="lineNum">     486 </span>            :                         iterator_range&lt;ForwardIteratorT&gt; Res=
<span class="lineNum">     487 </span>            :                             ::boost::algorithm::detail::find_tail_impl( Begin, End, -m_N );
<span class="lineNum">     488 </span>            : 
<span class="lineNum">     489 </span>            :                         return ::boost::make_iterator_range(Begin, Res.begin());
<span class="lineNum">     490 </span>            :                     }
<span class="lineNum">     491 </span>            :                 }
<span class="lineNum">     492 </span>            : 
<span class="lineNum">     493 </span>            :             private:
<span class="lineNum">     494 </span>            :                 int m_N;
<span class="lineNum">     495 </span>            :             };
<span class="lineNum">     496 </span>            : 
<span class="lineNum">     497 </span>            : //  find tail functor -----------------------------------------------//
<span class="lineNum">     498 </span>            : 
<span class="lineNum">     499 </span>            : 
<span class="lineNum">     500 </span>            :             // find a tail in the sequence ( functor )
<span class="lineNum">     501 </span>            :             /*
<span class="lineNum">     502 </span>            :                 This functor find a tail of the specified range. For
<span class="lineNum">     503 </span>            :                 a specified N, the head is a subsequence of N starting
<span class="lineNum">     504 </span>            :                 elements of the range.
<span class="lineNum">     505 </span>            :             */
<span class="lineNum">     506 </span>            :             struct tail_finderF
<span class="lineNum">     507 </span>            :             {
<span class="lineNum">     508 </span>            :                 // Construction
<span class="lineNum">     509 </span>            :                 tail_finderF( int N ) : m_N(N) {}
<span class="lineNum">     510 </span>            : 
<span class="lineNum">     511 </span>            :                 // Operation
<span class="lineNum">     512 </span>            :                 template&lt; typename ForwardIteratorT &gt;
<span class="lineNum">     513 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     514 </span>            :                 operator()(
<span class="lineNum">     515 </span>            :                     ForwardIteratorT Begin,
<span class="lineNum">     516 </span>            :                     ForwardIteratorT End ) const
<span class="lineNum">     517 </span>            :                 {
<span class="lineNum">     518 </span>            :                     if(m_N&gt;=0)
<span class="lineNum">     519 </span>            :                     {
<span class="lineNum">     520 </span>            :                         return ::boost::algorithm::detail::find_tail_impl( Begin, End, m_N );
<span class="lineNum">     521 </span>            :                     }
<span class="lineNum">     522 </span>            :                     else
<span class="lineNum">     523 </span>            :                     {
<span class="lineNum">     524 </span>            :                         iterator_range&lt;ForwardIteratorT&gt; Res=
<span class="lineNum">     525 </span>            :                             ::boost::algorithm::detail::find_head_impl( Begin, End, -m_N );
<span class="lineNum">     526 </span>            : 
<span class="lineNum">     527 </span>            :                         return ::boost::make_iterator_range(Res.end(), End);
<span class="lineNum">     528 </span>            :                     }
<span class="lineNum">     529 </span>            :                 }
<span class="lineNum">     530 </span>            : 
<span class="lineNum">     531 </span>            :             private:
<span class="lineNum">     532 </span>            :                 int m_N;
<span class="lineNum">     533 </span>            :             };
<span class="lineNum">     534 </span>            : 
<span class="lineNum">     535 </span>            : //  find token functor -----------------------------------------------//
<span class="lineNum">     536 </span>            : 
<span class="lineNum">     537 </span>            :             // find a token in a sequence ( functor )
<span class="lineNum">     538 </span>            :             /*
<span class="lineNum">     539 </span>            :                 This find functor finds a token specified be a predicate
<span class="lineNum">     540 </span>            :                 in a sequence. It is equivalent of std::find algorithm,
<span class="lineNum">     541 </span>            :                 with an exception that it return range instead of a single
<span class="lineNum">     542 </span>            :                 iterator.
<span class="lineNum">     543 </span>            : 
<span class="lineNum">     544 </span>            :                 If bCompress is set to true, adjacent matching tokens are
<span class="lineNum">     545 </span>            :                 concatenated into one match.
<span class="lineNum">     546 </span>            :             */
<span class="lineNum">     547 </span>            :             template&lt; typename PredicateT &gt;
<span class="lineNum">     548 </span><span class="lineCov">         25 :             struct token_finderF</span>
<span class="lineNum">     549 </span>            :             {
<span class="lineNum">     550 </span>            :                 // Construction
<span class="lineNum">     551 </span>            :                 token_finderF(
<span class="lineNum">     552 </span>            :                     PredicateT Pred,
<span class="lineNum">     553 </span>            :                     token_compress_mode_type eCompress=token_compress_off ) :
<span class="lineNum">     554 </span><span class="lineCov">          1 :                         m_Pred(Pred), m_eCompress(eCompress) {}</span>
<span class="lineNum">     555 </span>            : 
<span class="lineNum">     556 </span>            :                 // Operation
<a name="557"><span class="lineNum">     557 </span>            :                 template&lt; typename ForwardIteratorT &gt;</a>
<span class="lineNum">     558 </span>            :                 iterator_range&lt;ForwardIteratorT&gt;
<span class="lineNum">     559 </span><span class="lineCov">          1 :                 operator()(</span>
<span class="lineNum">     560 </span>            :                     ForwardIteratorT Begin,
<span class="lineNum">     561 </span>            :                     ForwardIteratorT End ) const
<span class="lineNum">     562 </span>            :                 {
<span class="lineNum">     563 </span>            :                     typedef iterator_range&lt;ForwardIteratorT&gt; result_type;
<span class="lineNum">     564 </span>            : 
<span class="lineNum">     565 </span><span class="lineCov">          1 :                     ForwardIteratorT It=std::find_if( Begin, End, m_Pred );</span>
<span class="lineNum">     566 </span>            : 
<span class="lineNum">     567 </span><span class="lineCov">          1 :                     if( It==End )</span>
<span class="lineNum">     568 </span>            :                     {
<span class="lineNum">     569 </span><span class="lineCov">          1 :                         return result_type( End, End );</span>
<span class="lineNum">     570 </span>            :                     }
<span class="lineNum">     571 </span>            :                     else
<span class="lineNum">     572 </span>            :                     {
<span class="lineNum">     573 </span>            :                         ForwardIteratorT It2=It;
<span class="lineNum">     574 </span>            : 
<span class="lineNum">     575 </span><span class="lineNoCov">          0 :                         if( m_eCompress==token_compress_on )</span>
<span class="lineNum">     576 </span>            :                         {
<span class="lineNum">     577 </span>            :                             // Find first non-matching character
<span class="lineNum">     578 </span><span class="lineNoCov">          0 :                             while( It2!=End &amp;&amp; m_Pred(*It2) ) ++It2;</span>
<span class="lineNum">     579 </span>            :                         }
<span class="lineNum">     580 </span>            :                         else
<span class="lineNum">     581 </span>            :                         {
<span class="lineNum">     582 </span>            :                             // Advance by one position
<span class="lineNum">     583 </span>            :                             ++It2;
<span class="lineNum">     584 </span>            :                         }
<span class="lineNum">     585 </span>            : 
<span class="lineNum">     586 </span><span class="lineNoCov">          0 :                         return result_type( It, It2 );</span>
<span class="lineNum">     587 </span>            :                     }
<span class="lineNum">     588 </span>            :                 }
<span class="lineNum">     589 </span>            : 
<span class="lineNum">     590 </span>            :             private:
<span class="lineNum">     591 </span>            :                 PredicateT m_Pred;
<span class="lineNum">     592 </span>            :                 token_compress_mode_type m_eCompress;
<span class="lineNum">     593 </span>            :             };
<span class="lineNum">     594 </span>            : 
<span class="lineNum">     595 </span>            : //  find range functor -----------------------------------------------//
<span class="lineNum">     596 </span>            : 
<span class="lineNum">     597 </span>            :             // find a range in the sequence ( functor )
<span class="lineNum">     598 </span>            :             /*
<span class="lineNum">     599 </span>            :                 This functor actually does not perform any find operation.
<span class="lineNum">     600 </span>            :                 It always returns given iterator range as a result.
<span class="lineNum">     601 </span>            :             */
<span class="lineNum">     602 </span>            :             template&lt;typename ForwardIterator1T&gt;
<span class="lineNum">     603 </span>            :             struct range_finderF
<span class="lineNum">     604 </span>            :             {
<span class="lineNum">     605 </span>            :                 typedef ForwardIterator1T input_iterator_type;
<span class="lineNum">     606 </span>            :                 typedef iterator_range&lt;input_iterator_type&gt; result_type;
<span class="lineNum">     607 </span>            : 
<span class="lineNum">     608 </span>            :                 // Construction
<span class="lineNum">     609 </span>            :                 range_finderF(
<span class="lineNum">     610 </span>            :                     input_iterator_type Begin,
<span class="lineNum">     611 </span>            :                     input_iterator_type End ) : m_Range(Begin, End) {}
<span class="lineNum">     612 </span>            : 
<span class="lineNum">     613 </span>            :                 range_finderF(const iterator_range&lt;input_iterator_type&gt;&amp; Range) :
<span class="lineNum">     614 </span>            :                     m_Range(Range) {}
<span class="lineNum">     615 </span>            : 
<span class="lineNum">     616 </span>            :                 // Operation
<span class="lineNum">     617 </span>            :                 template&lt; typename ForwardIterator2T &gt;
<span class="lineNum">     618 </span>            :                 iterator_range&lt;ForwardIterator2T&gt;
<span class="lineNum">     619 </span>            :                 operator()(
<span class="lineNum">     620 </span>            :                     ForwardIterator2T,
<span class="lineNum">     621 </span>            :                     ForwardIterator2T ) const
<span class="lineNum">     622 </span>            :                 {
<span class="lineNum">     623 </span>            : #if BOOST_WORKAROUND( __MWERKS__, &lt;= 0x3003 ) 
<span class="lineNum">     624 </span>            :                     return iterator_range&lt;const ForwardIterator2T&gt;(this-&gt;m_Range);
<span class="lineNum">     625 </span>            : #else
<span class="lineNum">     626 </span>            :                     return m_Range;
<span class="lineNum">     627 </span>            : #endif
<span class="lineNum">     628 </span>            :                 }
<span class="lineNum">     629 </span>            : 
<span class="lineNum">     630 </span>            :             private:
<span class="lineNum">     631 </span>            :                 iterator_range&lt;input_iterator_type&gt; m_Range;
<span class="lineNum">     632 </span>            :             };
<span class="lineNum">     633 </span>            : 
<span class="lineNum">     634 </span>            : 
<span class="lineNum">     635 </span>            :         } // namespace detail
<span class="lineNum">     636 </span>            :     } // namespace algorithm
<span class="lineNum">     637 </span>            : } // namespace boost
<span class="lineNum">     638 </span>            : 
<span class="lineNum">     639 </span>            : #endif  // BOOST_STRING_FINDER_DETAIL_HPP
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
